from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-10 14:13:57.502107
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 10, Aug, 2021
Time: 14:14:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6061
Nobs: 379.000 HQIC: -46.1701
Log likelihood: 4069.54 FPE: 6.13047e-21
AIC: -46.5411 Det(Omega_mle): 4.84954e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488564 0.096785 5.048 0.000
L1.Burgenland 0.101842 0.049746 2.047 0.041
L1.Kärnten -0.116874 0.024118 -4.846 0.000
L1.Niederösterreich 0.173794 0.106179 1.637 0.102
L1.Oberösterreich 0.075895 0.104599 0.726 0.468
L1.Salzburg 0.298262 0.051185 5.827 0.000
L1.Steiermark 0.015857 0.067781 0.234 0.815
L1.Tirol 0.134779 0.053661 2.512 0.012
L1.Vorarlberg -0.110864 0.048166 -2.302 0.021
L1.Wien -0.056294 0.093827 -0.600 0.549
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.027811 0.232980 -0.119 0.905
L1.Burgenland -0.038663 0.119747 -0.323 0.747
L1.Kärnten 0.035969 0.058056 0.620 0.536
L1.Niederösterreich -0.207222 0.255592 -0.811 0.418
L1.Oberösterreich 0.550371 0.251788 2.186 0.029
L1.Salzburg 0.308309 0.123212 2.502 0.012
L1.Steiermark 0.107667 0.163161 0.660 0.509
L1.Tirol 0.298667 0.129172 2.312 0.021
L1.Vorarlberg -0.017780 0.115944 -0.153 0.878
L1.Wien 0.003264 0.225860 0.014 0.988
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.264244 0.050005 5.284 0.000
L1.Burgenland 0.094912 0.025702 3.693 0.000
L1.Kärnten -0.004062 0.012461 -0.326 0.744
L1.Niederösterreich 0.230148 0.054858 4.195 0.000
L1.Oberösterreich 0.152624 0.054042 2.824 0.005
L1.Salzburg 0.035396 0.026445 1.338 0.181
L1.Steiermark 0.010765 0.035020 0.307 0.759
L1.Tirol 0.077829 0.027725 2.807 0.005
L1.Vorarlberg 0.057765 0.024885 2.321 0.020
L1.Wien 0.081022 0.048477 1.671 0.095
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200718 0.048967 4.099 0.000
L1.Burgenland 0.041943 0.025168 1.667 0.096
L1.Kärnten -0.006650 0.012202 -0.545 0.586
L1.Niederösterreich 0.126355 0.053719 2.352 0.019
L1.Oberösterreich 0.305523 0.052920 5.773 0.000
L1.Salzburg 0.099882 0.025896 3.857 0.000
L1.Steiermark 0.140400 0.034292 4.094 0.000
L1.Tirol 0.077832 0.027149 2.867 0.004
L1.Vorarlberg 0.055993 0.024369 2.298 0.022
L1.Wien -0.043318 0.047470 -0.913 0.361
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205986 0.098249 2.097 0.036
L1.Burgenland -0.058053 0.050498 -1.150 0.250
L1.Kärnten -0.038158 0.024482 -1.559 0.119
L1.Niederösterreich 0.069177 0.107785 0.642 0.521
L1.Oberösterreich 0.197670 0.106181 1.862 0.063
L1.Salzburg 0.266316 0.051959 5.125 0.000
L1.Steiermark 0.078686 0.068806 1.144 0.253
L1.Tirol 0.126614 0.054473 2.324 0.020
L1.Vorarlberg 0.120174 0.048894 2.458 0.014
L1.Wien 0.035821 0.095247 0.376 0.707
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.035289 0.077003 0.458 0.647
L1.Burgenland 0.027476 0.039578 0.694 0.488
L1.Kärnten 0.051082 0.019188 2.662 0.008
L1.Niederösterreich 0.197396 0.084477 2.337 0.019
L1.Oberösterreich 0.340578 0.083220 4.093 0.000
L1.Salzburg 0.048014 0.040723 1.179 0.238
L1.Steiermark -0.000507 0.053927 -0.009 0.992
L1.Tirol 0.114564 0.042693 2.683 0.007
L1.Vorarlberg 0.062651 0.038321 1.635 0.102
L1.Wien 0.124572 0.074650 1.669 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165494 0.093636 1.767 0.077
L1.Burgenland 0.027100 0.048127 0.563 0.573
L1.Kärnten -0.059227 0.023333 -2.538 0.011
L1.Niederösterreich -0.101473 0.102723 -0.988 0.323
L1.Oberösterreich 0.191217 0.101195 1.890 0.059
L1.Salzburg 0.029042 0.049519 0.586 0.558
L1.Steiermark 0.297710 0.065575 4.540 0.000
L1.Tirol 0.489990 0.051915 9.438 0.000
L1.Vorarlberg 0.073623 0.046598 1.580 0.114
L1.Wien -0.110120 0.090774 -1.213 0.225
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158310 0.102089 1.551 0.121
L1.Burgenland -0.006123 0.052472 -0.117 0.907
L1.Kärnten 0.063257 0.025439 2.487 0.013
L1.Niederösterreich 0.198510 0.111997 1.772 0.076
L1.Oberösterreich -0.128466 0.110330 -1.164 0.244
L1.Salzburg 0.247491 0.053990 4.584 0.000
L1.Steiermark 0.157465 0.071495 2.202 0.028
L1.Tirol 0.049182 0.056602 0.869 0.385
L1.Vorarlberg 0.122492 0.050805 2.411 0.016
L1.Wien 0.141124 0.098969 1.426 0.154
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.522510 0.055004 9.499 0.000
L1.Burgenland -0.022598 0.028271 -0.799 0.424
L1.Kärnten -0.010042 0.013706 -0.733 0.464
L1.Niederösterreich 0.189050 0.060342 3.133 0.002
L1.Oberösterreich 0.250670 0.059444 4.217 0.000
L1.Salzburg 0.022043 0.029089 0.758 0.449
L1.Steiermark -0.024467 0.038520 -0.635 0.525
L1.Tirol 0.075026 0.030496 2.460 0.014
L1.Vorarlberg 0.059955 0.027373 2.190 0.029
L1.Wien -0.060469 0.053323 -1.134 0.257
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022227 0.064850 0.128250 0.121329 0.034565 0.065260 -0.002810 0.168553
Kärnten 0.022227 1.000000 -0.059314 0.128975 0.044643 0.068804 0.458241 -0.093688 0.100173
Niederösterreich 0.064850 -0.059314 1.000000 0.284896 0.088694 0.270257 0.014187 0.141673 0.254903
Oberösterreich 0.128250 0.128975 0.284896 1.000000 0.177773 0.294303 0.166475 0.121740 0.127168
Salzburg 0.121329 0.044643 0.088694 0.177773 1.000000 0.125672 0.046776 0.108677 0.051044
Steiermark 0.034565 0.068804 0.270257 0.294303 0.125672 1.000000 0.130599 0.087612 -0.026357
Tirol 0.065260 0.458241 0.014187 0.166475 0.046776 0.130599 1.000000 0.037466 0.124785
Vorarlberg -0.002810 -0.093688 0.141673 0.121740 0.108677 0.087612 0.037466 1.000000 -0.046672
Wien 0.168553 0.100173 0.254903 0.127168 0.051044 -0.026357 0.124785 -0.046672 1.000000